<template>
  <div>
    <h4>我想开店！请完善以下信息</h4>
    <el-form ref="form" label-width="80px">
      <el-form-item label="店铺名称">
        <el-input
          v-model="shop.name"
          minlength="3"
          maxlength="12"
          :show-word-limit="true"
          size="small"
          style="width:240px"
        ></el-input>
      </el-form-item>
      <el-form-item label="店铺简介">
        <el-input
          type="textarea"
          v-model="shop.desc"
          maxlength="200"
          :show-word-limit="true"
          style="width:500px"
        ></el-input>
      </el-form-item>
      <el-form-item label="店铺类型">
        <el-radio-group v-model="shop.Type">
          <el-radio label="个人店铺"></el-radio>
          <el-radio label="企业店铺"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="店铺地址">
        <el-radio-group v-model="shop.address">
          <el-radio label="大陆"></el-radio>
          <el-radio label="香港"></el-radio>
          <el-radio label="台湾"></el-radio>
          <el-radio label="海外"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="注册资金">
        <el-input
          v-model="shop.registerMoney"
          maxlength="10"
          :show-word-limit="true"
          size="small"
          style="width:140px"
        ></el-input>元
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即申请</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapstate, mapActions } = createNamespacedHelpers("shop");
export default {
  data() {
    return {
      shop: {
        name: "",
        merchantName: "",
        desc: "",
        Type: "",
        address: "",
        registerMoney: "",
        state: 1
      }
    };
  },
  methods: {
    ...mapActions(["createShopAsync"]),
    async onSubmit() {
      if (
        this.shop.name &&
        this.shop.merchantName &&
        this.shop.desc &&
        this.shop.Type &&
        this.shop.address &&
        this.shop.registerMoney
      ) {
        let data = await this.createShopAsync(this.shop);
        if (data._id) {
          this.open();
        } else {
          this.$notify({
            title: "警告",
            message: data.msg,
            type: "warning"
          });
        }
      } else {
        this.$notify({
          title: "警告",
          message: "请把信息填写完整",
          type: "warning"
        });
      }
    },
    open() {
      this.$alert("申请提交成功，审核在7个工作日内完成！", "开店申请", {
        confirmButtonText: "确定",
        callback: action => {
          this.$router.push("/merchant/MerchantRead");
        }
      });
    }
  },
  created() {
    this.shop.merchantName = sessionStorage.getItem("userName");
  }
};
</script>

<style>
</style>